<template>
  <div class="main-app">
    <el-card class="box-card">
      <el-form :inline="true" :model="formInline" class="form-inline">

        <el-form-item label="废物名称:">
          <el-input v-model="formInline.name" clearable />
        </el-form-item>
        <el-form-item label="状态:">
          <el-select v-model="formInline.status" placeholder="请选择" clearable>
            <el-option v-for="item in wastObjFormTransportFromStateOption" :key="item.value" :label="item.label"
                       :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="search">
            查询
          </el-button>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-refresh-right" @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <div class="show-result">
      <el-form :inline="true" class="form-inline">
        <el-button icon="el-icon-arrow-left" @click="cancel">
          返 回
        </el-button>
      </el-form>
      <div class="result">
        <el-table ref="multipleTable" v-loading="loading" border :data="tableData" tooltip-effect="dark"
                  style="width: 100%"
        >
          <el-table-column prop="name" label="废物名称" />
          <el-table-column prop="number" label="数字识别码" />
          <el-table-column prop="categoryContent" label="废物类别" />
          <el-table-column prop="codeContent" label="废物代码" />
          <el-table-column prop="hazardousSubstancesName" label="危害成分" />
          <el-table-column prop="orgName" label="产废单位" width="200" />
          <el-table-column prop="wastWeight" label="重量(吨)" />

          <el-table-column prop="characteristicContent" label="危险特性" />
          <el-table-column prop="containerCategory" label="容器类型" width="120">
            <template slot-scope="scope">
              <el-tag style="width: 100%; text-align: center;" effect="dark">
                {{ scope.row.containerCategory | parseContainerTypeType }}
              </el-tag>
            </template>
          </el-table-column>

          <el-table-column prop="physicalProperties" label="废物形态" width="120">
            <template slot-scope="scope">
              <el-tag style="width: 100%; text-align: center;" effect="dark">
                {{ scope.row.physicalProperties | parsePhysicalPropertiesType }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="status" label="状态" width="120">
            <template slot-scope="scope">
              <el-tag style="width: 100%; text-align: center;" effect="dark">
                {{ scope.row.status | statusType }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="describe" label="备注" width="300" />
        </el-table>
        <div class="page">
          <el-pagination background :current-page.sync="currentPage" layout="total,prev, pager, next,sizes"
                         :total="total" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" @current-change="handleCurrentChange"
                         @size-change="handleSizeChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// Table组件相关逻辑，需要引用
import {
  pageMixin
} from "../../../mixins/index";
import {
  wastObjFormTransportFromState,
  PhysicalProperties,
  ContainerType
} from "../../../utils/resource.js";
import {
  getTransportFromWastObjList,
} from '../../../api/wastecomponey.js';

export default {
  filters: {
    parseDate(value) {
      if (value) {
        return value.replace("T", " ");
      }
    },
    parseType(value) {
      if (value != null) {
        return wastObjFormTransportFromState.find((p) => p.value === `${value}`).label;
      }
    },
    statusType(value) {
      if (value != null) {
        return wastObjFormTransportFromState.find((p) => p.value === `${value}`).label;
      }
    },
    parsePhysicalPropertiesType(value) {
      if (value != null) {
        return PhysicalProperties.find((p) => p.value === `${value}`).label;
      }
    },
    parseContainerTypeType(value) {
      if (value != null) {
        return ContainerType.find((p) => p.value === `${value}`).label;
      }
    },

  },
  mixins: [pageMixin],

  data() {
    return {
      id: '',
      wastObjFormTransportFromStateOption: wastObjFormTransportFromState,
      formInline: {
        transportTime: ["", ""],
        name: "",
        status: "",
      },

    };
  },
  async created() {
    const {
      id
    } = this.$route.params;
    if (id) {
      this.id = id;
      await this.init();
    }

    await this.init();
  },
  methods: {
    async init() {
      this.tableData = [];
      this.loading = true;
      var searchStatus = '';
      if (this.formInline.status === '30') {
        searchStatus = '30,40'
      }
      const {
        data,
        count
      } = await getTransportFromWastObjList({
        limit: this.pageSize,
        page: this.currentPage,
        searchParam: JSON.stringify({
          ReceiptId: this.id,
          Name: this.formInline.name,
          Status: searchStatus
        })
      });
      data.forEach(item => {
        if (item.status === "40") {
          item.status = "30"
        }
      })
      this.tableData = data;
      this.total = count;
      this.loading = false;
    },

    async search() {
      await this.init();
    },
    async reset() {
      this.formInline = {
        name: "",
        status: "",
        transportTime: "",
      };
      await this.init();
    },

    // handleSizeChange(val) {},
    // handleCurrentChange(val) {},
    // handleSelectionChange() {},

    report() {},

    cancel() {
      this.$router.push("/wastereceipt/orderquery");
    },

  },
};
</script>

<style lang="scss" scoped>
  .result {
    margin-top: 10px;
  }

  .page {
    margin-top: 20px;
    text-align: right;
    margin-bottom: 40px;
  }

  .show-result {
    margin-top: 10px;
  }
</style>
